package com.xique.door.service.impl;

import com.xique.door.bean.dao.CompanyUserCountDAO;
import com.xique.door.bean.domain.UserCompany;
import com.xique.door.mapper.UserCompanyMapper;
import com.xique.door.service.IUserCompanyService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户企业中间表Service业务层处理
 *
 * @author ww
 * @date 2021-12-21
 */
@Service
public class UserCompanyServiceImpl implements IUserCompanyService
{
    @Autowired
    private UserCompanyMapper userCompanyMapper;

    /**
     * 查询用户企业中间表
     *
     * @param userId 用户企业中间表ID
     * @return 用户企业中间表
     */
    @Override
    public UserCompany selectUserCompanyById(Long userId)
    {
        return userCompanyMapper.selectUserCompanyById(userId);
    }

    /**
     * 查询用户企业中间表列表
     *
     * @param userCompany 用户企业中间表
     * @return 用户企业中间表
     */
    @Override
    public List<UserCompany> selectUserCompanyList(UserCompany userCompany)
    {
        return userCompanyMapper.selectUserCompanyList(userCompany);
    }

    /**
     * 新增用户企业中间表
     *
     * @param userCompany 用户企业中间表
     * @return 结果
     */
    @Override
    public int insertUserCompany(UserCompany userCompany)
    {
        return userCompanyMapper.insertUserCompany(userCompany);
    }

    /**
     * 修改用户企业中间表
     *
     * @param userCompany 用户企业中间表
     * @return 结果
     */
    @Override
    public int updateUserCompany(UserCompany userCompany)
    {
        return userCompanyMapper.updateUserCompany(userCompany);
    }

    /**
     * 批量删除用户企业中间表
     *
     * @param userIds 需要删除的用户企业中间表ID
     * @return 结果
     */
    @Override
    public int deleteUserCompanyByIds(Long[] userIds)
    {
        return userCompanyMapper.deleteUserCompanyByIds(userIds);
    }

    /**
     * 删除用户企业中间表信息
     *
     * @param userId 用户企业中间表ID
     * @return 结果
     */
    @Override
    public int deleteUserCompanyById(Long userId)
    {
        return userCompanyMapper.deleteUserCompanyById(userId);
    }

    @Override
    public List<CompanyUserCountDAO> selectCompanyUserCountByCompanyIds(List<Long> companyIds) {
        if (CollectionUtils.isEmpty(companyIds)) {
            return new ArrayList<>(0);
        }
        return userCompanyMapper.selectCompanyUserCountByCompanyIds(companyIds);
    }
}
